﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ThouShaltNotBrick.Logic.Resources;
using ThouShaltNotBrick.Models;

namespace ThouShaltNotBrick.Logic.GeneralObjects
{
    public sealed class Level
    {
        #region Properties
        #region Name
        /// <summary>
        /// Name property.
        /// </summary>
        public string Name { get; private set; }
        #endregion

        private List<Brick> mBricks;
        #endregion

        #region Constructors
        public Level(
            string pCampaignName,
            string pLevelName,
            GameResources pGameResources,
            BrickStatesAndTypes pBrickStatesAndTypes)
        {
            Initialize(pCampaignName, pLevelName, pGameResources, pBrickStatesAndTypes);
        }
        #endregion

        #region Methods
        private void Initialize(
            string pCampaignName,
            string pLevelName,
            GameResources pGameResources,
            BrickStatesAndTypes pBrickStatesAndTypes)
        {
            LevelData levelData = pGameResources.GetLevelData(pCampaignName, pLevelName);

            Name = levelData.Name;

            List<BrickData> brickDataList = levelData.GetBricks();
            mBricks = new List<Brick>();
            foreach (BrickData brickData in brickDataList)
            {
                int row = brickData.Row;
                int col = brickData.Column;
                BrickType brickType = pBrickStatesAndTypes.GetBrickType(brickData.TypeName);

                Brick brick = new Brick(row, col, brickType, brickData.InitialBrickStateIndex);
                mBricks.Add(brick);
            }
        }

        public List<Brick> GetAllBricks()
        {
            return new List<Brick>(mBricks);
        }
        #endregion
    }
}